<?php
class Page extends AppModel {
    var $name = 'Page';
    var $pagesTable = 'pages';
    var $dienstenTable = 'diensten';
    var $newsTable = 'nieuwsitems';
    
    public function getContent( $page ) {
        $queryStr = "SELECT title, content
        FROM `{$this->pagesTable}`
        WHERE `page` = '$page'";
        
        $result = $this->query( $queryStr );
        $content = array();
//         debug($queryStr);
//         debug($result);
        
        if( isset( $result ) && !empty( $result ) ) {
            foreach( $result as $res ) {
                $temp            = $res[$this->pagesTable];
                $temp['title']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["title"] ) ) );
                $temp['content'] = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["content"] ) ) );
                $content         = $temp;
            }
        }

        return $content;
    }


    public function getDienst( $page ) {
        $queryStr = "SELECT title, content
        FROM `{$this->dienstenTable}`
        WHERE `type` = '$page'";
        
        $result = $this->query( $queryStr );
        $content = array();
//         debug($queryStr);
//         debug($result);
        
        if( isset( $result ) && !empty( $result ) ) {
            foreach( $result as $res ) {
                $temp            = $res[$this->dienstenTable];
                $temp['title']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["title"] ) ) );
                $temp['content'] = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["content"] ) ) );
                $content         = $temp;
            }
        }

        return $content;
    }
    
    public function getNewsItems( $noItems ) {
        $myQuery = "SELECT * FROM `{$this->newsTable}`
                       ORDER BY `{$this->newsTable}`.`key` DESC".
                       (($noItems==0)?"":" LIMIT {$noItems}");
        
//         debug($myQuery);
        
        $result = $this->query( $myQuery );
        
        $content = array();        
        $i = 0;
        if( isset( $result ) && !empty( $result ) ) {
            foreach( $result as $res ) {
                $temp            = $res[$this->newsTable];
                $temp['title']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["title"] ) ) );
                $temp['content'] = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["content"] ) ) );
                $temp['image']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["image"] ) ) );
                $temp['date']    = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["date"] ) ) );
                $content[$i]     = $temp;
                $i++;
            }
        }
        
        return $content;
    }

    public function getNewsItem( $item ) {
        $myQuery = "SELECT * FROM `{$this->newsTable}`
                        WHERE `{$this->newsTable}`.`key` = '$item'";
    
        //         debug($myQuery);
    
        $result = $this->query( $myQuery );
    
        $content = array();
        if( isset( $result ) && !empty( $result ) ) {
            foreach( $result as $res ) {
                $temp            = $res[$this->newsTable];
                $temp['title']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["title"] ) ) );
                $temp['content'] = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["content"] ) ) );
                $temp['image']   = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["image"] ) ) );
                $temp['date']    = stripslashes( html_entity_decode( htmlspecialchars_decode( $temp["date"] ) ) );
                $content         = $temp;
                }
        }
    
            return $content;
        }
    
}